# -*- coding: utf-8 -*-
# flake8: noqa

from qiniu import Auth, put_file, etag

access_key = 'x0abHv3YMHSK_Gii2KM9CVPIC25EYg__LrkBId5c'
secret_key = 'oNXf-Ibo7E341Zz2QXfWBrlZP0BVTV-Z86fxcqGE'
q = Auth(access_key, secret_key)
bucket_name = 'lixianhe-cdn'
key = 'a.png'
policy = {
    'callbackUrl': 'https://hooks.upyun.com/IZRYHt8xT',
    'callbackBody': '{"bucket":"$(bucket)","name":"$(fname)","hash":"$(etag)","size":"$(fsize)","key":"$(key)","mime":"$(mimeType)","exif":"$(exif)","imageInfo":$(imageInfo),"fprefix":"$(fprefix)","avinfo":$(avinfo)}',
    'callbackBodyType': 'application/json',
    'fileType': 1
}
token = q.upload_token(bucket_name, key, 3600, policy)
print(token)
localfile = '/Users/lixianhe/Downloads/a.png'
ret, info = put_file(token, key, localfile, version='v2')
print(info)
assert ret['key'] == key
assert ret['hash'] == etag(localfile)
